/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.data.store;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.feiyue.basic.reader.pojo.Book;
import com.feiyue.basic.reader.pojo.Chapter;
import com.feiyue.basic.reader.pojo.Content;
import com.feiyue.basic.reader.pojo.Describe;
import com.feiyue.basic.reader.pojo.Sort;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

public final class Api {
	public static final ChapterStore chapterStore;
	protected static final String chapterUrl = "/chapter.shtml";
	public static final ContentStore contentStore;
	protected static final String contentUrl = "/content.shtml";
	protected static final String decribeUrl = "/describe.shtml";
	public static final DescribeStore describeStore;
	protected static final String rootUrl = "http://119.145.70.74:8992/ibooks";
	public static final SortItemStore sortItemStore;
	protected static final String sortItemUrl = "/novel.shtml";
	public static final SortStore sortStore = SortStore.getInstance();
	protected static final String sortUrl = "/category.shtml";
	private static final String total = "10";

	static {
		sortItemStore = SortItemStore.getInstance();
		describeStore = DescribeStore.getInstance();
		chapterStore = ChapterStore.getInstance();
		contentStore = ContentStore.getInstance();
	}

	public static final Bitmap getBitMap(String paramString) {
		return getBitMaps("http://api.paopaoyouxi.com/haotingFM" + paramString,
				0);
	}

	public static final Bitmap getBitMap2(String paramString) {
		return getBitMaps(paramString, 0);
	}

	public static Bitmap getBitMaps(String s, int i)
    {
        Bitmap bitmap = null;
        Bitmap bitmap1 = null;
        Bitmap bitmap2;
        try
        {
            URLConnection urlconnection = (new URL(s)).openConnection();
            urlconnection.connect();
            InputStream inputstream = urlconnection.getInputStream();
            BufferedInputStream bufferedinputstream = new BufferedInputStream(inputstream);
            if (bufferedinputstream != null) {
                bitmap1 = BitmapFactory.decodeStream(bufferedinputstream);
                bufferedinputstream.close();
            }
            
            inputstream.close();
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        if (i != 1 || bitmap1 != null) {
            if (bitmap1 == null) {
                bitmap2 = getBitMaps(s, i);
                bitmap1 = bitmap2;
            }
        }
        
        bitmap = bitmap1;

        return bitmap;
    }

	public static final List<Chapter> getChapter(String paramString1,
			String paramString2) throws Exception {
		String[] arrayOfString1 = { "nid", "page", "total" };
		String[] arrayOfString2 = { paramString1, paramString2, "10" };
		chapterStore.setParamsName(arrayOfString1);
		chapterStore.setParamsValue(arrayOfString2);
		chapterStore.setUrl("http://119.145.70.74:8992/ibooks/chapter.shtml");
		return chapterStore.getList();
	}

	public static final List<Book> getCommend(String paramString)
			throws Exception {
		String[] arrayOfString1 = { "type", "page", "total" };
		String[] arrayOfString2 = { "recommend", paramString, "10" };
		sortItemStore.setParamsName(arrayOfString1);
		sortItemStore.setParamsValue(arrayOfString2);
		sortItemStore.setUrl("http://119.145.70.74:8992/ibooks/novel.shtml");
		return sortItemStore.getList();
	}

	public static final Content getContent(String paramString) throws Exception {
		String[] arrayOfString1 = { "cid" };
		String[] arrayOfString2 = { paramString };
		contentStore.setParamsName(arrayOfString1);
		contentStore.setParamsValue(arrayOfString2);
		contentStore.setUrl("http://119.145.70.74:8992/ibooks/content.shtml");
		return contentStore.getList();
	}

	public static final List<Describe> getDescribe(String paramString)
			throws Exception {
		String[] arrayOfString1 = { "nid" };
		String[] arrayOfString2 = { paramString };
		describeStore.setParamsName(arrayOfString1);
		describeStore.setParamsValue(arrayOfString2);
		describeStore.setUrl("http://119.145.70.74:8992/ibooks/describe.shtml");
		return describeStore.getList();
	}

	public static final Drawable getDrawable(String paramString) {
		InputStream localInputStream = null;
		try {
			localInputStream = (InputStream) new URL(paramString).getContent();
			return Drawable.createFromStream(localInputStream, "src");
		} catch (MalformedURLException localMalformedURLException) {
			localMalformedURLException.printStackTrace();
		} catch (IOException localIOException) {
			localIOException.printStackTrace();
		} finally {
			if (localInputStream != null) {
				try {
					localInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
		return null;
	}

	public static final List<Book> getHit(String paramString) throws Exception {
		String[] arrayOfString1 = { "type", "page", "total" };
		String[] arrayOfString2 = { "hot", paramString, "10" };
		sortItemStore.setParamsName(arrayOfString1);
		sortItemStore.setParamsValue(arrayOfString2);
		sortItemStore.setUrl("http://119.145.70.74:8992/ibooks/novel.shtml");
		return sortItemStore.getList();
	}

	public static final List<Book> getNew(String paramString) throws Exception {
		String[] arrayOfString1 = { "type", "page", "total" };
		String[] arrayOfString2 = { "newest", paramString, "10" };
		sortItemStore.setParamsName(arrayOfString1);
		sortItemStore.setParamsValue(arrayOfString2);
		sortItemStore.setUrl("http://119.145.70.74:8992/ibooks/novel.shtml");
		return sortItemStore.getList();
	}

	public static final List<Sort> getSort() throws Exception {
		String[] arrayOfString1 = { "p" };
		String[] arrayOfString2 = { "category" };
		sortStore.setParamsName(arrayOfString1);
		sortStore.setParamsValue(arrayOfString2);
		sortStore.setUrl("http://119.145.70.74:8992/ibooks/category.shtml");
		return sortStore.getList();
	}

	public static final List<Book> getSortItem(String paramString1,
			String paramString2) throws Exception {
		String[] arrayOfString1 = { "cid", "page", "total" };
		String[] arrayOfString2 = { paramString1, paramString2, "10" };
		sortItemStore.setParamsName(arrayOfString1);
		sortItemStore.setParamsValue(arrayOfString2);
		sortItemStore.setUrl("http://119.145.70.74:8992/ibooks/novel.shtml");
		return sortItemStore.getList();
	}
}